<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<!--查询部门表单-->
<form class="layui-form" action="" lay-filter="departmentForm">
    <div class="layui-form-item">
        <label class="layui-form-label">产品类别：</label>
        <div class="layui-input-inline">
            <select name="s_name">
                <option value="">请选择类别</option>
                <option value="水果类" name="s_name" lay-verify="s_name">水果类</option>
                <option value="饮料类" name="s_name" lay-verify="s_name">饮料类</option>
                <option value="日用类" name="s_name" lay-verify="s_name">日用类</option>
                <option value="食物类" name="s_name" lay-verify="s_name">食物类</option>
            </select>
        </div>
        <label class="layui-form-label">产品名称：</label>
        <div class="layui-input-inline">
            <select name="p_name">
                <option value="">请选择商品</option>
                <option value="苹果" name="p_name" lay-verify="p_name">苹果</option>
                <option value="香蕉" name="p_name" lay-verify="p_name">香蕉</option>
                <option value="可乐" name="p_name" lay-verify="p_name">可乐</option>
                <option value="雪碧" name="p_name" lay-verify="p_name">雪碧</option>
                <option value="洗面奶" name="p_name" lay-verify="p_name">洗面奶</option>
                <option value="大米" name="p_name" lay-verify="p_name">大米</option>
                <option value="小麦" name="p_name" lay-verify="p_name">小麦</option>
            </select>
        </div>
        <button type="button" id="formsubmit" class="layui-btn" lay-submit="" lay-filter="demo1">查询</button>
    </div>
</form>
<!--部门表单-->
<table class="layui-hide" id="test" lay-filter="test"></table>

<!--p_name跳转连接，d代表当前行'{{}}'会自动转义-->
<script type="text/html" id="pNameTpl">
    <a href="area.html" class="layui-table-link">{{d.p_name}}</a>
</script>

<script src="../../layui/layui.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    layui.use(['table', 'form', 'layer'], function () {
        var table = layui.table;
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;


        table.render({
            id: 'departmentTable'
            , elem: '#test'
            , url: '/firstWeb/sort_DP'
            , title: '产品管理'
            , where: {}
            , cols: [[
                {field: 'p_id', title: '序列号'}
                , {field: 'p_name', title: '产品名称', templet: '#pNameTpl'}
                , {field: 'p_area', title: '产地'}
                , {field: 's_name', title: '类别名称'}
                , {field: 'p_ml', title: '规格'}
                , {field: 'p_is', title: '商品状态'}
            ]]
            , page: true // 默认一页十条
            , limit: 12
            , limits: [1, 5, 10, 20]
        });

        function tableReload() {
            var data = form.val('departmentForm');
            table.reload('departmentTable', {
                where: data
                , page: {
                    curr: 1
                }
            })
        }

        $("#formsubmit").click(function () {
            tableReload();
        })

        //监听提交
        form.on('submit(demo1)', function (data) {
                p_name = data.value,
                s_name = data.value
        });

    });
</script>

</body>
</html>